<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <canvas id="c1" width="600" height="400">
        浏览器不支持canvas
    </canvas>
    <script>
        /** @type {HTMLCanvasElement} */
        var c1 = document.getElementById("c1");
        var ctx = c1.getContext("2d")

        var img = new Image();
        img.src = './img/head.png';

        img.onload = function(){
            var pattern = ctx.createPattern(img,"repeat");
            //repeat  no-repeat    repeat-x  repeat-y
            ctx.fillStyle = pattern;
            ctx.fillRect(0,0,600,400);
        }
    </script>
</body>
</html>